﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Xpus.Website.Utilities;

namespace Xpus.Website.Data
{
	partial class File
	{
		#region 字段验证
		/// <summary>
		/// FileName属性长度最大值。
		/// </summary>
		public const int FileNameMaxLength = 1024;

		/// <summary>
		/// Extension属性长度最大值。
		/// </summary>
		public const int ExtensionMaxLength = 1024;

		/// <summary>
		/// MimeType属性长度最大值。
		/// </summary>
		public const int MimeTypeMaxLength = 64;

		/// <summary>
		/// UploadIP属性长度最大值。
		/// </summary>
		public const int UploadIPMaxLength = 128;

		partial void OnFileNameChanging(string value)
		{
			FieldChecker.CheckFieldNotNull("FileName", value);
			FieldChecker.CheckFieldTooLong("FileName", value, FileNameMaxLength);
		}

		partial void OnExtensionChanging(string value)
		{
			FieldChecker.CheckFieldNotNull("Extension", value);
			FieldChecker.CheckFieldTooLong("Extension", value, ExtensionMaxLength);
		}

		partial void OnMimeTypeChanging(string value)
		{
			FieldChecker.CheckFieldNotNull("MimeType", value);
			FieldChecker.CheckFieldTooLong("MimeType", value, MimeTypeMaxLength);

			if(!Utilities.MimeType.IsValidMimeType(value))
				throw new ArgumentException(string.Format(LanguageUtility.GetString("'{0}' is not a valid MIME type."), value), "MimeType");
		}

		partial void OnUploadIPChanging(string value)
		{
			FieldChecker.CheckFieldNotNull("UploadIP", value);
			FieldChecker.CheckFieldTooLong("UploadIP", value, UploadIPMaxLength);
		}
		#endregion
	}
}
